﻿using System.Drawing;
using FileLibrary.Enums;
using ShuntingScheduleUserControl.Helper;
using ShuntingScheduleUserControl.Model;

namespace ShuntingScheduleUserControl.View
{
    public class ViewNode
    {
        public Node Node { get; }
        public DrawContext DrawContext { get; }

        public ViewNode(Node node, DrawContext drawContext)
        {
            Node = node;
            DrawContext = drawContext;
        }

        public int MachId { get; set; }
        public int Bottom { get; set; }
        public int Top { get; set; }
        public int Left { get; set; }
        public int Middle { get; set; }
        public int TimeLeft { get; set; }
        public SizeF Size { get; set; }
        public PointF WordsPoint { get; set; }

        public void Draw(Graphics g, Rectangle rec)
        {
            g.DrawLine(DrawHelper.PenBlack1, Left, Bottom, rec.Right, Bottom);
            if (Node.TrackPosEnum != TrackPosEnum.None && DrawContext.DrawPosLine)
            {
                g.DrawLine(DrawHelper.PenBlack1Dot, TimeLeft, Middle, rec.Right, Middle);
            }

            if (WordsPoint.IsEmpty)
            {
                Size = g.MeasureString(Node.Name, DrawHelper.FtDefault);
                WordsPoint = new PointF(Left, Bottom - (DrawContext.NodeHeight + Size.Height) / 2);
            }

            g.DrawString(Node.Name, DrawHelper.FtNodeName, DrawHelper.BrushTimeName, WordsPoint);
        }
    }
}